<!DOCTYPE html>
<html>
<head>
<script src="../../resources/ahem.js"></script>
<script src="../../resources/js-test.js" type="text/javascript"></script>
<style>
    body {
        font: 20px Ahem;
    }
</style>
</head>
<body>
<p> Bug <a href="http://webkit.org/b/86390">86390</a>: Expose FrameSelection::absoluteCaretBounds via window.internals</p>
<p>This test demonstrates the usage of internals.absoluteCaretBounds()</p>
<div id="testDiv" CONTENTEDITABLE>abcd</div>
<div id="console"></div>
</body>
<script>
    var caretRects = [];
    function verifyCaretRect(left, top, width, height)
    {
        if (window.internals) {
            var index = caretRects.length;
            caretRects.push(internals.absoluteCaretBounds());
            shouldBe("caretRects[" + index + "].left", left.toString());
            shouldBe("caretRects[" + index + "].top", top.toString());
            shouldBe("caretRects[" + index + "].width", width.toString());
            shouldBe("caretRects[" + index + "].height", height.toString());
        }
    }

    var textNode = document.getElementById("testDiv").firstChild;
    getSelection().collapse(textNode, 0);  // before a
    verifyCaretRect(8, 160, 1, 20);
    getSelection().collapse(textNode, 1);  // after a
    verifyCaretRect(28, 160, 1, 20);
    getSelection().collapse(textNode, 2);  // after b
    verifyCaretRect(48, 160, 1, 20);
    getSelection().collapse(textNode, 3);  // after c
    verifyCaretRect(68, 160, 1, 20);
    getSelection().collapse(textNode, 4);  // after d
    verifyCaretRect(88, 160, 1, 20);
</script>
</html>
